package com.fuhe.chen.vendingmachine.service.impl;

import com.fuhe.chen.vendingmachine.common.redis.RedisUtils;
import com.fuhe.chen.vendingmachine.dao.CommoditySpecificationDao;
import com.fuhe.chen.vendingmachine.pojo.CommoditySpecification;
import com.fuhe.chen.vendingmachine.service.ICommoditySpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.fuhe.chen.vendingmachine.constant.CacheConstant.COMMODIIES_ALL_ON_SALE;

@Service
public class CommoditySpecificationServiceImpl implements ICommoditySpecificationService {

    @Autowired
    CommoditySpecificationDao commoditySpecificationDao;

    @Autowired
    RedisUtils redisUtils;

    @Override
    public List<CommoditySpecification> queryCommoditySpecification(Integer commodity_id) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        return commoditySpecificationDao.findByCommodityId(commodity_id);
    }

    @Override
    public void addCommoditySpecification(CommoditySpecification specification) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        commoditySpecificationDao.add(specification);
    }

    @Override
    public void updateCommoditySpecification(CommoditySpecification specification) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        commoditySpecificationDao.update(specification);
    }

    @Override
    public void deleteCommoditySpecification(Integer id) {
        redisUtils.delAll(COMMODIIES_ALL_ON_SALE);
        commoditySpecificationDao.delete(id);
    }
}
